/**
 * CreateServer
 * 
 * 28/12/2013
 * 
 * Copyright GPL
 */
package com.jtmproject;

import android.app.Activity;
import android.os.Bundle;
import android.view.KeyEvent;

import com.jtmproject.bluetooth.Server;

/**
 * This class waits for clients
 * 
 * @author Javier Tejedor
 */
public class CreateServer extends Activity {

	private Server server;

	/* (non-Javadoc)
	 * @see android.app.Activity#onCreate(android.os.Bundle)
	 */
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_create_server);

		server = new Server(this);

		//it saves the object to share between activities
		Server.setServer(server);
	}

	@Override
	protected void onDestroy() {
		//server.cancelConnection();
		super.onDestroy();
	}

	/* (non-Javadoc)
	 * @see android.app.Activity#onKeyDown(int, android.view.KeyEvent)
	 */
	@Override
	public boolean onKeyDown(int keyCode, KeyEvent event) {
		if ((keyCode == KeyEvent.KEYCODE_BACK)) {
			onBackPressed();
		}
		return true;
	}

	/* (non-Javadoc)
	 * @see android.app.Activity#onBackPressed()
	 */
	@Override
	public void onBackPressed() {
		super.onBackPressed();   
		server.cancelConnection();
		finish();

	}

}
